home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 4: GNU Archives / Linux Cubed Series 4 - GNU Archives.iso / gnu / glibc-1.09 / glibc-1 / glibc-1.09.1 / sysdeps / unix / bsd / sun / sunos4 / speed.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-07-18  |  2.7 KB  |  114 lines

  1. /* `struct termios' speed frobnication functions.  SunOS 4 version.
  2. Copyright (C) 1991, 1992, 1993 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4.  
  5. The GNU C Library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Library General Public License as
  7. published by the Free Software Foundation; either version 2 of the
  8. License, or (at your option) any later version.
  9.  
  10. The GNU C Library is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13. Library General Public License for more details.
  14.  
  15. You should have received a copy of the GNU Library General Public
  16. License along with the GNU C Library; see the file COPYING.LIB.  If
  17. not, write to the Free Software Foundation, Inc., 675 Mass Ave,
  18. Cambridge, MA 02139, USA.  */
  19.  
  20. #include <ansidecl.h>
  21. #include <stddef.h>
  22. #include <errno.h>
  23. #include <termios.h>
  24.  
  25. static CONST speed_t speeds[] =
  26.   {
  27.     0,
  28.     50,
  29.     75,
  30.     110,
  31.     134,
  32.     150,
  33.     200,
  34.     300,
  35.     600,
  36.     1200,
  37.     1800,
  38.     2400,
  39.     4800,
  40.     9600,
  41.     19200,
  42.     38400,
  43.   };
  44.  
  45.  
  46. /* Return the output baud rate stored in *TERMIOS_P.  */
  47. speed_t
  48. DEFUN(cfgetospeed, (termios_p), CONST struct termios *termios_p)
  49. {
  50.   return termios_p->c_cflag & CBAUD;
  51. }
  52.  
  53. /* Return the input baud rate stored in *TERMIOS_P.  */
  54. speed_t
  55. DEFUN(cfgetispeed, (termios_p), CONST struct termios *termios_p)
  56. {
  57.   return (termios_p->c_cflag & CIBAUD) >> IBSHIFT;
  58. }
  59.  
  60. /* Set the output baud rate stored in *TERMIOS_P to SPEED.  */
  61. int
  62. DEFUN(cfsetospeed, (termios_p, speed),
  63.       struct termios *termios_p AND speed_t speed)
  64. {
  65.   register unsigned int i;
  66.  
  67.   if (termios_p == NULL)
  68.     {
  69.       errno = EINVAL;
  70.       return -1;
  71.     }
  72.  
  73.   /* This allows either B1200 or 1200 to work.    XXX
  74.      Do we really want to try to support this, given that
  75.      fetching the speed must return one or the other?  */
  76.  
  77.   for (i = 0; i < sizeof (speeds) / sizeof (speeds[0]); ++i)
  78.     if (i == speed || speeds[i] == speed)
  79.       {
  80.     termios_p->c_cflag &= ~CBAUD;
  81.     termios_p->c_cflag |= i;
  82.     return 0;
  83.       }
  84.  
  85.   errno = EINVAL;
  86.   return -1;
  87. }
  88.  
  89. /* Set the input baud rate stored in *TERMIOS_P to SPEED.  */
  90. int
  91. DEFUN(cfsetispeed, (termios_p, speed),
  92.       struct termios *termios_p AND speed_t speed)
  93. {
  94.   register unsigned int i;
  95.  
  96.   if (termios_p == NULL)
  97.     {
  98.       errno = EINVAL;
  99.       return -1;
  100.     }
  101.  
  102.   /* See comment in cfsetospeed (above).  */
  103.   for (i = 0; i < sizeof (speeds) / sizeof (speeds[0]); ++i)
  104.     if (i == speed || speeds[i] == speed)
  105.       {
  106.     termios_p->c_cflag &= ~CIBAUD;
  107.     termios_p->c_cflag |= i << IBSHIFT;
  108.     return 0;
  109.       }
  110.  
  111.   errno = EINVAL;
  112.   return -1;
  113. }
  114.